package com.terrynoya.fight.combat
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.emuns.MoveType;
	import com.terrynoya.fight.emuns.StateTypeEnum;
	import com.terrynoya.fight.stateMachine.triggers.StateType;
	import com.terrynoya.geom.MVector2D;

	public class DefensiveInfo
	{
		private var _chara:Character;
		
		private var _hitTime:int;
		private var _hitShakeTime:int;
		
		private var _hitStateType:int;
		
		private var _hitDef:HitDefinition;
		
		private var _blocked:Boolean;
		
		public function DefensiveInfo(chara:Character)
		{
			this._chara = chara;
			this._hitDef = new HitDefinition();
		}

		public function get blocked():Boolean
		{
			return _blocked;
		}

		public function set blocked(value:Boolean):void
		{
			_blocked = value;
		}

		public function get falling():Boolean 
		{
			return this._chara.moveType == MoveType.BeingHit ? this._hitDef.fall : false;
		}
		
		public function get hitDef():HitDefinition
		{
			return _hitDef;
		}

		public function set hitDef(value:HitDefinition):void
		{
			_hitDef = value;
		}

		public function get hitShakeTime():int
		{
			return _hitShakeTime;
		}

		public function set hitShakeTime(value:int):void
		{
			_hitShakeTime = value;
		}

		public function get hitStateType():int
		{
			return _hitStateType;
		}

		public function set hitStateType(value:int):void
		{
			_hitStateType = value;
		}

		public function get hitTime():int
		{
			return _hitTime;
		}

		public function set hitTime(value:int):void
		{
			_hitTime = value;
		}
		
		public function update():void
		{
			if(this._hitShakeTime > 0)
			{
				this._hitShakeTime--;
			}
			else if(this._hitTime > -1)
			{
				this._hitTime--;
			}
			if(this._hitShakeTime < 0)
			{
				this._hitShakeTime = 0;
			}
			if(this._hitTime < 0)
			{
				this._hitTime = 0;
			}
		}
		
		public function getHitVelocity():MVector2D
		{
			var vel:MVector2D;
			if(this._blocked)
			{
				vel = this.hitStateType == StateTypeEnum.Airborne ? this._hitDef.airGuardVelocity : this._hitDef.groundGuardVelocity;
			}
			else
			{
				vel = this.hitStateType == StateTypeEnum.Airborne ? this._hitDef.airHitVelocity : this._hitDef.groundVelocity;
			}
			return vel;
		}
		
		public function onHit(hitDef:HitDefinition,attacker:Character,blocked:Boolean):void
		{
			this.hitDef.setDef(hitDef);
			this._hitStateType = this._chara.state;
			this._chara.moveType = MoveType.BeingHit;
			this._blocked = blocked;
			
			if(blocked == true)
			{
			
			}
			else
			{
				this._hitShakeTime = hitDef.shakeTime;
			}
		}

	}
}